define(["app","js/signature/typeView","js/init", 'js/utils','js/util/socketUtil',"text!app/signature/type.html","js/signature/model"], 
	function(app, typeView,base,Utils,initSocket,typeSource,model) {
	
	
	var bindings = [		
			
		
		//导航链接
		{
			element: '#signature-type-page .back-link',
			event: 'click',
			handler: clickBack
		}
		,
		
		{
			element: '.signature-type-page .type-link',
			event: 'click',
			handler: clickType
		}	
	];

	/**
	 * 回退按钮事件
	 */
	function clickBack(){
		if(!app.mainView){
			app = app.getApp();
		}
		
		var _cv = app.f7.getCurrentView();

		if(_cv && _cv.router){
			_cv.router.load({pageName:'signature/main'});
		}
	}
	
	/**
	 * 点击具体类型事件（显示表单事件）
	 */
	function clickType(e){
		if(!app.mainView){
			app = app.getApp();
		}
		
		var _cv = app.f7.getCurrentView();
		
		
		var _code,_name
		if(e && e.currentTarget){
			var _el = $(e.currentTarget)
			_code = _el.attr('pid')
			_name = _el.attr('pname')
		}

		if(_cv && _cv.router){
			app.f7.showPreloader('loading...');
			_cv.router.load({url:"app/signature/formList.html",query:{code:_code,name:_name}});
		}
	}
	
	function init(query){	
		
		if(!app.mainView){
			app = app.getApp();
		}
		
		if(query.code){
			
			var rows =[]
			if(model.type){
				
				
				var _title
				//显示分类命名
				$.each(model.type,function(i,o){
					if(o.code == query.code){
						_title = o.name;
						return false;
					}
				})				
				var _el = $('#signature-type-page .biz-title')
				_el.html(_title);
			}
			
			if(model.module){
				//显示分类命名
				$.each(model.module,function(i,o){
					if(o.type){
						
						$.each(o.type,function(ti,to){
							
							if(to == query.code){
								
								var d = {code:o.code,name:o.name,type:to};
								rows.push(d);
							}
						})
					}
				})	
				
			}
			
			typeView.render({
				model	: rows ,
				bindings: bindings
			});
			
			app.f7.hidePreloader();
		}
			
		//signatureView.render({			
		//	bindings: bindings
		//});
	}
	

	return {
		init: init
	};
});